﻿#include "VTKmArray.h"
#include <vtkm/cont/Algorithm.h>
#include <vtkm/worklet/WorkletMapField.h>
using psreal = vtkm::FloatDefault;

struct SetZeroFunctor : public vtkm::worklet::WorkletMapField
{
  using ControlSignature = void(FieldInOut);
  using ExecutionSignature = void(_1);
  template<typename T>
  VTKM_EXEC void operator()(T& v) const
  {
    v = 0;
  }
};

struct ScaleFunctor : public vtkm::worklet::WorkletMapField
{
  ScaleFunctor(psreal scale)
    : m_scale(scale)
  {
  }
  using ControlSignature = void(FieldInOut);
  using ExecutionSignature = void(_1);
  template<typename T>
  VTKM_EXEC void operator()(T& v) const
  {
    v *= m_scale;
  }
  psreal m_scale;
};

template<typename T>
inline void VTKmArray<T>::zero()
{
  vtkm::cont::Invoker{}(SetZeroFunctor{}, this->m_data);
}

template<typename T>
VTKmArray<T>& VTKmArray<T>::operator*=(const T a)
{
  vtkm::cont::Invoker{}(ScaleFunctor{a}, this->m_data);
}
